Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SO_BINDTODEVICE option #408

Merged
merged 1 commit into from
Oct 23, 2023

Conversation

leso-kn
Copy link
Contributor

@leso-kn leso-kn commented Sep 1, 2023

This PR adds support for setting SO_BINDTODEVICE through master:setoption().

In combination with :bind() this allows for binding to unix tunnel interfaces (e.g. an OpenVPN connection), aka source based split tunneling.

Example

-- Force TCP connection through an OpenVPN tunnel on the 'tun0' interface
local client = socket.tcp()
client:bind('10.10.0.5', 0) -- bind to local IP address of 'tun0' on a random port
client:setoption('bindtodevice', 'tun0') -- bind to 'tun0' interface

-- Fetch example.org through tun0 connection:
assert(client:connect('example.org', 80)
client:send('HTTP/1.1 GET /')
print(client:receive('*a'))

@alerque
Copy link
Member

alerque commented Sep 2, 2023

Any idea why CI jobs got stuck here?

@leso-kn
Copy link
Contributor Author

leso-kn commented Oct 14, 2023

@alerque I believe it also got stuck here: !396

Perhaps a restart may fix it? I do not have permission to view the job logs unfortunately.

@alerque
Copy link
Member

alerque commented Oct 14, 2023

I just tweaked your commit and force pushed it just for the effect of poking CI in the eye with a sharp stick. It wasn't giving me the option to restart jobs either. Maybe they will run now.

@leso-kn
Copy link
Contributor Author

leso-kn commented Oct 14, 2023

@alerque Ah thanks :) Yeah that seemed to work, I just added a fix to handle the call macOS where the option does not exist. Should pass the CI now.

@leso-kn
Copy link
Contributor Author

leso-kn commented Oct 14, 2023

Please feel free to poke it again in case it does not start in a bit, perhaps it only triggers on commits signed by maintainers.

src/options.c Show resolved Hide resolved
@alerque alerque merged commit f741a88 into lunarmodules:master Oct 23, 2023
13 checks passed
@rpatters1
Copy link
Contributor

rpatters1 commented Oct 26, 2023

This PR has broken my static Windows build, because SO_BINDTODEVICE is not defined. Any suggestions how to fix it? (Also IFNAMSIZ not defined.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants